Dekoratives Banner

Render and Mail


    This script renders all queued items in an open project, and sends an email report to indicate when the render has completed. It makes use of two other scripts which follow, email_methods.jsx (to send the email properly) and email_setup.jsx (which establishes the sender, recipient, and email server).

    We start by establishing conditions under which the script will run. An open project with at least one item queued is required.

    {
        var safeToRunScript = true;
       
        safeToRunScript = app.project != null;
        if (! app.project) {
            alert ("A project must be open to run this script.");
        }
        if (safeToRunScript) {
        debugger;
            //check the render queue and make certain at least one item is queued
            safeToRunScript = false;
            for (i = 1; i <= app.project.renderQueue.numItems; ++i) {
                if (app.project.renderQueue.item(i).status ==
                RQItemStatus.QUEUED) {
                    safeToRunScript = true;
                    break;
                }
            }
            if (! safeToRunScript) {
                alert ("You do not have any items set to render.");
            }
        }

    Now we check whether we have email settings already saved in the Preferences. If so, we don't need to prompt the user. If not, we run the email_setup.jsx script which prompts the user as to the mail gateway, sender and recipient addresses. If there are saved settings that you need to change, you can always run email_setup.jsx to make new settings which overwrite the existing ones.

        if (safeToRunScript) {
           
            var settings = app.settings;
            if ( !settings.haveSetting("Email Settings", "Mail Server") ||
                !settings.haveSetting("Email Settings", "Reply-to Address") ||
                !settings.haveSetting("Email Settings", "Render Report
                    Recipient")){
       
                // We don't have the settings yet, so run email_setup.jsx
                // to prompt for them
                var email_setupfile = new File("email_setup.jsx");
                email_setupfile.open("r");
                eval( email_setupfile.read() );
                email_setupfile.close();
            }
       
            var myQueue = app.project.renderQueue //creates a shortcut for RQ
           

    Now we're ready to render. Once rendering is complete, the script creates a text string for the email message which contains the start time of the render, the render time of each item in the queue, and the total render time.

            myQueue.render();
               
            var projectName = "Unsaved Project";
            if (app.project.file) {
                projectName = app.project.file.name;
            }
            var myMessage = "Rendering of " + projectName + " is complete.\n\n";
           

    Now email the message, using the three settings from the email_methods.jsx script which has been automatically run to prompt the user for the server, above.

            if ( !settings.haveSetting("Email Settings", "Mail Server") ||
                !settings.haveSetting("Email Settings", "Reply-to Address") ||
                !settings.haveSetting("Email Settings", "Render Report
                    Recipient")){
                alert("Can't send an email, I don't have all the settings I need.
                Aborting.");
            } else {
                // Load code from a file with handy emailing methods:
                var emailCodeFile = new File("email_methods.jsx");
                emailCodeFile.open("r");   
                eval( emailCodeFile.read() );
                emailCodeFile.close();

    Finally, we sesnd an error if for any reason we are unable to send the mail.

                var serverSetting = settings.getSetting("Email Settings", "Mail
                Server");
                var fromSetting = settings.getSetting("Email Settings", "Reply-
                to Address");
                var toSetting = settings.getSetting("Email Settings", "Render
                Report Recipient");
                var myMail = new EmailSocket(serverSetting);
                if (! myMail.send (fromSetting, toSetting, "AE Render Completed", myMessage) ) {
                    alert("Sending mail failed");
                }
            }
        }
    }